package com.tarena.test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.tarena.util.datasource.DBConnection;

public class PageResultDemo {
	public static void main(String[] args){
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			conn=DBConnection.getConnection();
			String sql = "select * from fuck_emp";
			ps=conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			rs=ps.executeQuery();
			int pageNo=10;
			int pageSize=5;
			int begin = (pageNo-1)*pageSize+1;
			rs.absolute(begin);
			for (int i = 1; i <= pageSize; i++) {
				System.out.println(rs.getInt(1));
				if (!rs.next()) {
					break;
				}
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBConnection.close(rs, ps, conn);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
